      *> File Name     000018_Inherit.cbl.
      *> Description   Inheriting class Dog from class Animal.
      *> Project Type  Console Application.
      *> CodePlex URL  http://cobol.codeplex.com
 
       program-id.   Main.
       repository.
           class animal      as "Animal"
           class dog         as "Dog"
           class sys-console as "System.Console"
           .
       working-storage section.
       01  a        animal.
       01  d        dog.
       01  newline  string  value type "System.Environment"::"NewLine".
       procedure division.
           move "Inheriting Class Dog from Class Animal"
               to sys-console::"Title"
               
           move Dog::"New"("St. Bernard", "Fido") to d
 
           display d::"Moniker" " is a " d::"Breed" "."
           display d::"Moniker" " says: " no advancing
           invoke d::"Speak"
 
           display newline "Upcasting this Dog to an Animal."           
           move d to a
           
           display "Animal is a " a::"GetType" "." *> still a dog
           display "Animal still says: " no advancing
           invoke a::"Speak" *> woof, woof
 
           display newline "Downcasting from Animal back to Dog."       
           move a as dog to d *> requires explicit cast
           
           display d::"Moniker" " the " d::"Breed" " still says: "
               no advancing
           invoke a::"Speak" *> woof, woof
 
           display newline "Press any key to continue . . . "
               no advancing
           invoke sys-console::"ReadKey"(true)
           .
       end program   Main.
 
       class-id.     Animal.
       working-storage section.
       01  _moniker  string. 
      *>
       method-id.    New.
       procedure division using by value moniker as string.
           move moniker to _moniker
           .
       end method    New.
      *>
       method-id.    get property Moniker.
       procedure division giving s as string.
           move _moniker to s.
       end method.
      *>
       method-id.    Speak.
       procedure division.
           display "[Silence]"
           .
       end method    Speak.
      *>
       end class     Animal.
 
       class-id.     Dog inherits type "Animal".
       working-storage section.
       01  _breed  string.
      *>
       method-id.    New.
       linkage section.
       01  breed    string.
       01  moniker  string.
       procedure division using by value breed, moniker.
           invoke super::"New"(moniker)
           move breed to _breed
           .
       end method    New.
      *>
       method-id.    get property Breed.
       procedure division giving s as string.
           move _breed to s.
       end method.
      *>
       method-id.    Speak override.
       procedure division.
           display "Woof, woof."
           .
       end method    Speak.
      *>
       end class     Dog.